import React from "react";
import { useState } from "react";
import "./3-GoodsImage.css";

export default function GoodsImage() {
  //声明状态保存下标
  let [index, setIndex] = useState(0);
  //声明图片数组
  let imageArr = [
    "/images/1.jpg",
    "/images/2.jpg",
    "/images/3.jpg",
    "/images/4.jpg",
    "/images/5.jpg",
  ];

  return (
    <div className="goods-image">
      <div className="big-image">
        <img src={imageArr[index]} alt="" />
      </div>
      <div className="small-images">
        {imageArr.map((item, key) => {
          return (
            <div key={key} className="item" onMouseOver={() => {
              //更新状态
              setIndex(key);
            }}>
              <img className={index === key ? "active" : ''} src={item} alt="" />
            </div>
          );
        })}
      </div>
    </div>
  );
}
